﻿# 设置你要更新的版本号（只改这里即可）
$APPVERSION = "1.3.1" 

# 文件路径
$csprojFile = "D:\0xh\videoplay\vlcplay\vlcplay.csproj"
$nsiFile    = "D:\0xh\videoplay\vlcplay\nsis\videoplay.nsi"

# 检查文件是否存在
if (-not (Test-Path $csprojFile)) {
    Write-Error "找不到文件: $csprojFile"
    exit
}
if (-not (Test-Path $nsiFile)) {
    Write-Error "找不到文件: $nsiFile"
    exit
}

# 替换 .csproj 文件中的 AssemblyVersion 和 FileVersion
Write-Host "正在更新 $csprojFile ..."

$assemblyVersion = "$APPVERSION.0"
$content = Get-Content -Path $csprojFile -Encoding utf8 -Raw
$content = $content -replace '<AssemblyVersion>.*?</AssemblyVersion>', "<AssemblyVersion>$assemblyVersion</AssemblyVersion>"
$content = $content -replace '<FileVersion>.*?</FileVersion>', "<FileVersion>$assemblyVersion</FileVersion>"

Set-Content -Path $csprojFile -Value $content -Encoding utf8

# 替换 .nsi 文件中的 PRODUCT_VERSION
Write-Host "正在更新 $nsiFile ..."

$content = Get-Content -Path $nsiFile -Encoding utf8 -Raw
$content = $content -replace '(!define PRODUCT_VERSION\s+)"[^"]+"', "`$1`"$APPVERSION`""

Set-Content -Path $nsiFile -Value $content -Encoding utf8

Write-Host "✅ 版本更新完成！新版本为：$APPVERSION"
cd D:\0xh\videoplay\vlcplay
dotnet clean
dotnet publish --runtime win-x64  --self-contained true
cd D:\0xh\videoplay\vlcplay\nsis
& "C:\Program Files (x86)\NSIS\makensis.exe" /INPUTCHARSET UTF8 videoplay.nsi
Copy-Item "D:\0xh\videoplay\vlcplay\nsis\Setup_九哈视觉_$APPVERSION.exe" "D:\sandboxvolumes\r\Setup_九哈视觉_$APPVERSION.exe" -Force